package org.example.greenhouse.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.greenhouse.entity.*;
import org.example.greenhouse.result.Result;
import org.example.greenhouse.service.SensorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@CrossOrigin
@RestController
@Api(tags= "传感器")
@RequestMapping("/Sensor")
public class SensorController {

    @Autowired
    private SensorService sensorService;

    @PostMapping("/update")
    @ApiOperation("更新一次传感器数据")
    public Result updateSensorData() {
        return sensorService.fetchAndSaveSensorData();
    }


    @GetMapping("/soli1/all")
    @ApiOperation("获取所有 soli1 数据")
    public Result getAllSoli1Data() {
        return sensorService.getAllSensorData(soli1.class);
    }

    @GetMapping("/soli2/all")
    @ApiOperation("获取所有 soli2 数据")
    public Result getAllSoli2Data() {
        return sensorService.getAllSensorData(soli2.class);
    }

    @GetMapping("/soli3/all")
    @ApiOperation("获取所有 soli3 数据")
    public Result getAllSoli3Data() {
        return sensorService.getAllSensorData(soli3.class);
    }

    @GetMapping("/soli4/all")
    @ApiOperation("获取所有 soli4 数据")
    public Result getAllSoli4Data() {
        return sensorService.getAllSensorData(soli4.class);
    }

    @GetMapping("/soli5/all")
    @ApiOperation("获取所有 soli5 数据")
    public Result getAllSoli5Data() {
        return sensorService.getAllSensorData(soli5.class);
    }
}